package com.wn.utils;

import java.net.URLEncoder;
import java.util.Date;

import com.wn.utils.HttpUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Station {

    public static final String APPKEY = "6be15cffbaf8348c";// 你的appkey
    public static final String URL = "https://api.jisuapi.com/train/station2s";
//    public static final String start = "杭州";// utf-8
//    public static final String end = "北京";// utf-8
    public static final int ishigh = 0;



    public static JSONObject Get(String start, String end, String date) throws Exception {
        String result = null;
        String url = URL + "?appkey=" + APPKEY + "&start=" + URLEncoder.encode(start, "utf-8") + "&end="
                + URLEncoder.encode(end, "utf-8") + "&ishigh=" + ishigh + "&date=" + date;
        JSONObject resultarr = null;
        try {
            result = HttpUtil.sendGet(url, "utf-8");
            System.out.println(result);
            JSONObject json = JSONObject.fromObject(result);
            System.out.println(json.getInt("status"));
            if (json.getInt("status") != 0) {
                System.out.println(json.getString("msg"));
            } else {
                resultarr = json.optJSONObject("result");
                System.out.println(resultarr);
//                for (int i = 0; i < resultarr.size(); i++) {
//                    JSONObject obj = (JSONObject) resultarr.opt(i);
//                    String trainno = obj.getString("trainno");
//                    String type = obj.getString("type");
//                    String station = obj.getString("station");
//                    String endstation = obj.getString("endstation");
//                    String departuretime = obj.getString("departuretime");
//                    String arrivaltime = obj.getString("arrivaltime");
//                    String sequenceno = obj.getString("sequenceno");
//                    String costtime = obj.getString("costtime");
//                    String distance = obj.getString("distance");
//                    String isend = obj.getString("isend");
//                    String pricesw = obj.getString("pricesw");
//                    String pricetd = obj.getString("pricetd");
//                    String pricegr1 = obj.getString("pricegr1");
//                    String pricegr2 = obj.getString("pricegr2");
//                    String pricerw1 = obj.getString("pricerw1");
//                    String pricerw2 = obj.getString("pricerw2");
//                    String priceyw1 = obj.getString("priceyw1");
//                    String priceyw2 = obj.getString("priceyw2");
//                    String priceyw3 = obj.getString("priceyw3");
//                    String priceyd = obj.getString("priceyd");
//                    String priceed = obj.getString("priceed");
//                    String pricerz = "";
//                    if (obj.has("pricerz")) {
//                        pricerz = obj.getString("pricerz");
//                    }
//                    String priceyz = "";
//                    if (obj.has("priceyz")) {
//                        priceyz = obj.getString("priceyz");
//                    }
//                    System.out.println(trainno + " " + type + " " + station + " " + endstation + " " + departuretime
//                            + " " + arrivaltime + " " + sequenceno + " " + costtime + " " + distance + " " + isend + " "
//                            + pricesw + " " + pricetd + " " + pricegr1 + " " + pricegr2 + " " + pricerw1 + " "
//                            + pricerw2 + " " + priceyw1 + " " + priceyw2 + " " + priceyw3 + " " + priceyd + " "
//                            + priceed + " " + pricerz + " " + priceyz);
//                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultarr;
    }

}
